<template>
  <div>
    
    <div class="chain-link-bar-wrapper">
  		<el-breadcrumb separator-class="el-icon-arrow-right">
	  		<el-breadcrumb-item>App管理者</el-breadcrumb-item>
	  		<el-breadcrumb-item to="/superman">App管理者列表</el-breadcrumb-item>
	  	</el-breadcrumb>  
	  </div>

  

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>App管理者列表</span>
        <el-button style="float: right;" type="primary" icon="el-icon-edit" @click="addEdit">添加</el-button>
      </div>

      <div class="app-diliver-10"></div>

      <div>
        <div class="app-display-inline app-margin-h-20">
          <el-input
            clearable
            placeholder="手机号"
            v-model="page.keyWord"
            style="width: 200px;"
              ></el-input>
        </div>
        <div class="app-display-inline app-margin-h-20">
          <SubmitButton
            type="primary" 
            plain
            icon="el-icon-search"
            :post-option="{
              url: searchUrl,
              data: page,
              callback: searchCB
            }"
            >搜索</SubmitButton>
        </div>
      </div>

      <div class="app-diliver-15"></div>
      <div class="app-diliver-15"></div>
      
      <el-table :data="supermanList" stripe border style="width: 100%" class="nc-table-btn-ctrl">
        <el-table-column type="index" :index="indexMethod">
        </el-table-column>
        
        <el-table-column
          label="会员"
          >
          <template slot-scope="scope">
            <img :src="scope.row.avatar" class="app-list-head-img">
          </template>
        </el-table-column>

        <el-table-column
          prop="realName"
          label="姓名"
          >
        </el-table-column>
        
        <el-table-column
          label="性别"
          >
          <template slot-scope="scope">
            <span v-if="scope.row.gender == null">未知</span>
            <span v-if="scope.row.gender == 'MALE'">男</span>
            <span v-if="scope.row.gender == 'FEMALE'">女</span>
          </template>
        </el-table-column>

        <el-table-column
          label="手机号"
          prop="phone"
          >
        </el-table-column>

        <el-table-column
          label="操作">
          <template slot-scope="scope">
            

            <NcButton
              size="mini"
              type="danger"
              :post-option="{url: deleteUrl, callback: getPage, confirm: '确定要移除管理账号【'+ scope.row.phone +'】吗？', data: {id: scope.row.id} }"
              class="app-margin-l-10 app-margin-v-5"
              >移除</NcButton>


          </template>
        </el-table-column>
      </el-table>


      <div class="pager-bar-wrapper">
        <el-pagination
          background
          layout="prev, pager, next, total"
          :total="page.totalRow"
          :page-size="page.pageSize"
          :current-page="page.pageNum"
          @current-change="pageNumChange"
          @prev-click="pageNumChange"
          @next-click="pageNumChange"
          @size-change="pageSizeChange"
          >
        </el-pagination>
      </div>

    </el-card>	


    <AddEditDialog :is-show="addEditVisible"></AddEditDialog>


  </div>
</template>


<script>

  import NcButton from '../common/NcButton'
  import SubmitButton from '../common/SubmitButton'

  import AddEditDialog from './AddEditDialog'

  import Api from '../../api/Api'
  import SupermanApi from '../../api/SupermanApi'

  import { mapGetters } from 'vuex'

  export default {
  	components: {
  		NcButton, SubmitButton, AddEditDialog
  	},
  	data(){
  	  return {
        supermanList: [],

        page: {
          keyWord: '',
          pageNum: 1,
          pageSize: 10
        },

        searchUrl: SupermanApi.URL_LIST,
        addUrl: SupermanApi.URL_ADD,
        deleteUrl: SupermanApi.URL_DELETE,

        addEditVisible: false,
  	  }
  	},
  	computed: {
  	  ...mapGetters(['hasPerm'])
  	},
  	created(){
  	  this.getPage();

      this.$root.eventHub.$on('closeEditDialog', this.hideEditDialog);
  	},
    beforeDestroy: function(){
      this.$root.eventHub.$off('closeEditDialog', this.hideEditDialog);
    },
  	methods: {
      searchCB(json){
        this.supermanList = json.list;
        this.setPage(json);
      },
      getPage(){
        SupermanApi.list(this.page, json=>{
          this.supermanList = json.list;
          this.setPage(json);
        });  
      },
      pageNumChange(pageNum){
        this.page.pageNum = pageNum;
        this.getPage();
      },
      pageSizeChange(pageSize){
        this.page.pageSize = pageSize;
        this.getPage();
      },
      setPage(json){
        this.page.pageNum = json.pageNum;
        this.page.pageSize = json.pageSize;
        this.page.totalRow = json.totalRow;
      },
      indexMethod(index){
        return index + 1 + (this.page.pageNum - 1) * this.page.pageSize
      },
      addEdit(){
        this.addEditVisible = true;
      },
      hideEditDialog(isSuccess){
        this.addEditVisible = false;
        
        if (isSuccess) {
          this.getPage();
        }
      },
  	}
  }
</script>
